var express = require('express');
var router = express.Router();
const BillModel = require('../../models/BillModel');
const authMiddleware = require('../../middware/authMiddleware');

// 记账本首页
router.get('/', function (req, res, next) {
  res.redirect('/list');
});

// 记账本
router.get('/list', authMiddleware, function (req, res, next) {

  BillModel.find().sort({ date: -1 }).then((data) => {
    res.render('list', { data: data });
  }).catch((err) => {
    res.render('list', { data: [] });
  });
});

// 添加账单
router.get('/add', authMiddleware, function (req, res, next) {
  res.render('add');
});


module.exports = router;
